// music.js

// 创建内部音频上下文
const innerAudioContext = wx.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.loop = true; // 循环播放
innerAudioContext.src = '/audios/dashboard.mp3'; // 音频资源地址

const wood_innerAudioContext = wx.createInnerAudioContext();
wood_innerAudioContext.autoplay = false;
wood_innerAudioContext.src = '/audios/percussive.mp3'; // 音频资源地址 

const metal_innerAudioContext = wx.createInnerAudioContext();
metal_innerAudioContext.autoplay = false;
metal_innerAudioContext.src = '/audios/metal_hit.mp3'; // 音频资源地址 

// 播放背景音乐函数
function playBackgroundMusic() {
  innerAudioContext.play(); // 继续播放
}

// 暂停背景音乐函数
function pauseBackgroundMusic() {
  innerAudioContext.pause(); // 暂停播放
}

function playWoodHitMusic() {
  wood_innerAudioContext.play();
}

function playMetalHitMusic() {
  metal_innerAudioContext.play();
}

function switchGameBackgroundMusic() {
  // 停止当前音乐
  innerAudioContext.stop();
  // 更新音频资源
  innerAudioContext.src = '/audios/gamebgm.mp3';

  // // 播放新的背景音乐
  // innerAudioContext.play();
}

function switchHomeBackgroundMusic() {
  // 停止当前音乐
  innerAudioContext.stop();
  // 更新音频资源
  innerAudioContext.src = '/audios/percussive.mp3';

  // // 播放新的背景音乐
  // innerAudioContext.play();
}

// 导出函数供其他文件使用
export {
  playBackgroundMusic,
  pauseBackgroundMusic,
  switchGameBackgroundMusic,
  switchHomeBackgroundMusic,
  playWoodHitMusic,
  playMetalHitMusic
};